Repository navigation
Docs (DialogMd data input): addresses confusion with injecting data - #3907
Conversation
| }) | ||
|
|
||
| export class DialogName { | ||
| constructor@Inject(MD_DIALOG_DATA) public data: any) { } |
There was a problem hiding this comment.
LOL how on earth? Must have hit the backspace key switching just before commit, that's super weird..
| value is forwarded as the result of the `afterClosed` promise. | ||
|
|
||
| ### Sharing Data with the Dialog component. | ||
| Depending on what you are doing you might want to share data with your dialog component. Angular has documentation that explains in general how to share data between any components using [`services`](https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service). |
There was a problem hiding this comment.
I don't think we should talk about services here, because they're a general Angular pattern. We should mention the data option instead.
There was a problem hiding this comment.
Yeah I agree. Should that ever be addressed in Angular Material documentation? Since a lot of the components are interactive, services seem pretty fundamental to the 'passing data problem' I started with Angular 3 months ago, and I was introduced to services by a few other developers asking why I was doing everything so backwards. I'm glad they brought it up, because in the long run it made my code a lot easier to understand.
- Is there a spot that we could expose users to services? (lots of us are beginners)
There was a problem hiding this comment.
I don't think it's Material's responsibility to expose users to services.
| }) | ||
|
|
||
| export class DialogName { | ||
| constructor( @Inject(MD_DIALOG_DATA) public data: any ) { } |
There was a problem hiding this comment.
We don't do spaces between the braces. It should be constructor(@Inject(MD_DIALOG_DATA) public data: any) { }.
|
|
||
| Passing outside data to your component is as simple as. | ||
| ```ts | ||
| import {MdDialog} from '@angular/material'; |
There was a problem hiding this comment.
In this example it's pretty obvious where MdDialog comes from so you can remove this line and the private dialog: MdDialog.
| private dialog: MdDialog; | ||
|
|
||
| let dialogRef = dialog.open(DialogName, { | ||
| data:'your data', |
There was a problem hiding this comment.
Add a space between the : and the string.
| Here is an example component you can pass data to. | ||
| ```ts | ||
| import {Component, Inject} from '@angular/core'; | ||
| import {MD_DIALOG_DATA} from '@angular/material'; |
There was a problem hiding this comment.
You can leave the imports here since the injection is slightly more convoluted.
| import {MD_DIALOG_DATA} from '@angular/material'; | ||
|
|
||
| @Component({ | ||
| selector: 'dialog-selector', |
There was a problem hiding this comment.
Try renaming this to something like your-dialog and the class to YourDialog.
| value is forwarded as the result of the `afterClosed` promise. | ||
|
|
||
| ### Sharing Data with the Dialog component. | ||
| Depending on what you are doing you might want to share data with your dialog component. The dialog component has a data option that you can include in order to pass data from the open to the dialog. |
There was a problem hiding this comment.
You should add backticks(`) around "data" in "The dialog component has a data option".
| value is forwarded as the result of the `afterClosed` promise. | ||
|
|
||
| ### Sharing Data with the Dialog component. | ||
| Depending on what you are doing you might want to share data with your dialog component. The dialog component has a `data` option allowing you to pass data to the component. |
There was a problem hiding this comment.
Sorry for all the requests, but can you reword this to "If you want to share data with your dialog, you can use the data option to pass information to the dialog component.". Also if you remove the "Passing outside data to your component is as simple as." sentence the PR will be good to go.
| }); | ||
| ``` | ||
|
|
||
| Here is an example component you can pass data to. |
There was a problem hiding this comment.
Can you change this to "To access the data in your dialog component, you have to use the MD_DIALOG_DATA injection token:"?
| constructor(@Inject(MD_DIALOG_DATA) public data: any) { } | ||
| } | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Can you reduce the amount of extra blank lines here? This is mainly for consistency.
|
Yeah your wording is a lot more crisp. I need to work on this my wording before I make more contributions. |
|
Just a small detail: the name of the dialog class in |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes Documentation is unclear about how to get data into a Dialog. #1947